package com.stylefeng.guns.core.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class InitID {
	//货物
	public static final String GOODS="GS";
	//员工
	public static final String EMPL="EM";
	//仓库
	public static final String WAREHOUSE="WH";
	//车辆
	public static final String CAR="CA";
	//发货人
	public static final String CONSIGNER="CR";
	//收货人
	public static final String CONSIGNEE="CE";
	//公司
	public static final String COMPANY="CM";
	//路线
	public static final String ROUTE="RU";
	//合同号
	public static final String CONTRACT_NUMBER="RU";
	
	private static InitID instance  = new InitID();
	
	private static int id;
	
	//获取唯一可用的对象
	   public static InitID getInstance(){
		  id++;
	      return instance;
	   }
	   
	private InitID(){}
	/**
	 * 生成无序的编号:类别+时间+四位随机数
	 * 用于货物、合同号、装车号
	 * @param type
	 * @return
	 */
	public static String initUnDisorderID(String type){
		String number = (int)((Math.random()*9+1)*1000) +"";
		Date now = new Date();
		DateFormat format = new SimpleDateFormat("yyyyMMdd");
		String dateStr = format.format(now);
		return  type+dateStr+number;
	}
	
	public static String initUnDisorderID(){
		String number = (int)((Math.random()*9+1)*1000) +"";
		Date now = new Date();
		DateFormat format = new SimpleDateFormat("yyyyMMdd");
		String dateStr = format.format(now);
		return  dateStr+number;
	}
	
	/**
	 * 生成有序的编号：类别+八位有序数
	 * 用于收发货人、员工、仓库编号、车号、公司代号
	 * @param type
	 * @return
	 */
	public static String initDisorderID(String type,int id){
		String number = id+"";
		int size = 8-number.length();
		StringBuffer str = new StringBuffer();
		str.append(type);
		for(int i=0;i<size;i++){
			str.append("0");
		}
		str.append(number);
		return  str.toString();
	}
	
	public static String initDisorderID(int id){
		String number = id+"";
		int size = 8-number.length();
		StringBuffer str = new StringBuffer();
		for(int i=0;i<size;i++){
			str.append("0");
		}
		str.append(number);
		return  str.toString();
	}
	
	
}
